//`index.js
var express = require('express')
var path = require('path')
var app = express()
    // var favicon = require('express-favicon')

console.log(__dirname);
console.log(path.join(__dirname, './dist/static/'));
// app.use('/static', express.static(path.join(__dirname, './dist/static/')))
// app.use('/data', express.static(path.join(__dirname, './src/data')))
// app.use('/img', express.static(path.join(__dirname, './src/assets/img')))

// app.use(favicon(path.join(__dirname, './favicon.ico')))

//设置跨域访问 控制好响应头
app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "X-Requested-With");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By", ' 3.2.1')
    res.header("Content-Type", "application/json;charset=utf-8");
    next();
});
app.get('/t', function(req, res) {
    res.send('web is ok');
});

app.get('/api/', function(req, res) {
    next();
});
// app.get('/train/', function(req, res) {
//     res.sendFile('index.html', { root: path.join(__dirname, './train') })
// })
// app.get('/bus/', function(req, res) {
//     res.sendFile('index.html', { root: path.join(__dirname, './bus') })
// })
// app.get('/user/', function(req, res) {
//     res.sendFile('index.html', { root: path.join(__dirname, './user') })
// })
// app.get('/wxpay/', function(req, res) {
//     res.sendFile('trainpay.htm', { root: path.join(__dirname, './') })
// })
// app.get('/', function(req, res) {
//     res.sendFile('index.html', { root: path.join(__dirname, './bus') })
// })

var server = app.listen(4040, '0.0.0.0', function() {

    var host = server.address().address
    var port = server.address().port

    console.log('infro-web listening at http://%s:%s', host, port)

});